
#include "main.h"

#define   PASSWORD_SIZE		8

//unsigned int Password;			  /* address of EEPROM */

//unsigned char EnterPassword[PASSWORD_SIZE];  

/* void Passwords_Init( void ) */
/* { */
/* 	E2_Str_LoadFrom( EnterPassword, E2_ADDR_PASSWORD_OWNER ); */
	
/* 	if ( EnterPassword[0] == 0 )	/\* Init. of first start *\/ */
/* 	{ */
/* 		E2_Str_SaveTo(E2_ADDR_PASSWORD_OWNER, "240673"); */
/* 		E2_Str_SaveTo(E2_ADDR_PASSWORD_MASTER, "523625"); */
/* 		E2_Str_SaveTo(E2_ADDR_PASSWORD_INSTALLER, "100200300"); */
/* 	} */
/* 	EnterPassword[0] = 0; */
/* } */

/* unsigned char CheckPassword( void ) */
/* { */
/* 	static unsigned char p = 0; */
/* 	unsigned char i = 0; */

/* 	if ( PressedKey == 0 ) */
/* 		return FALSE; */
	
/* 	/\* if ( PressedKey >= '0' && PressedKey <= '9' ) *\/ */
/* 	if ( PressedKey != KEY_OKAY ) */
/* 	{ */
/* 		if ( PressedKey == KEY_MENU ) */
/* 		{ */
/* 			ClearBuffer(EnterPassword, PASSWORD_SIZE); */
/* 			p = 0; */
/* 			return FALSE;  */
/* 		} */

/* 		EnterPassword[p] = PressedKey; */

/* 		if ( ++p == PASSWORD_SIZE ) */
/* 			p = 0; */
/* /\* 		lcd_goto(6,2); *\/ */
/* 		for ( i = 0; i < p; i++ ) */
/* 		{ */
/* 			lcd_putchar('*'); */
/* 		} */
/* 		i = 0; */
/* 	} */
/* 	else  */
/* 	{ */
/* 		//if ( StrCmp(Password, EnterPassword) == 0 ) */
/* 		if ( E2_StrCmp(EnterPassword, Password ) == 0 ) */
/* 		{ */
/* 			i = OK; */
/* 			if ( GoTo_If_Password_OK ) */
/* 			{ */
/* 				CurrentMenu = GoTo_If_Password_OK; */
/* 				GoTo_If_Password_OK = NULL; */
/* 				SysState = MENU; */
/* 			} */
/* 			else */
/* 				if ( SysState_If_Password_OK  ) */
/* 				{ */
/* 					SysState = SysState_If_Password_OK; */
/* 					SysState_If_Password_OK = 0; */
/* 				} */
/* 				else */
/* 					if ( Func != NULL ) */
/* 					{ */
/* 						Func(); */
/* 						Func = NULL; */
/* 					} */
/* 		} */
/* 		ClearBuffer(EnterPassword, PASSWORD_SIZE); */
/* 		p = 0; */
/* 		lcd_clear_str( 6, 2); */
/* 	} */
	
/* 	return i;   */
/* }  */
 
void Password_Generator( unsigned char* Password, unsigned char* PhoneNumber )
{
	unsigned char t, sl = StrLen(PhoneNumber), Buf[7];
	unsigned int wResult = 0;
	
	StrCpy(Buf, &PhoneNumber[sl-6] );

	for( t = 0; t < 6; t++ )
	{
      wResult = (wResult>>8)+(wResult<<8);

      wResult ^= Buf[t];

      wResult ^= ((wResult & 0xFF)>>4);

      wResult ^= (wResult<<8)<<4;

      wResult ^= ( ((wResult&0xFF)<<4) <<1);
	}

	wResult = wResult<<8 | wResult>>8; //swap bytes
   
   HexToChar(Password, (unsigned char*)&wResult, 2 );
}
